package lcspm.commands;

import java.util.List;
import lcspm.lib.ConfigHandler;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.ConfigCategory;
import net.minecraftforge.common.Property;

public class CommandDelWarp
  implements ICommand
{
  public int compareTo(Object o)
  {
    return 0;
  }

  public String getCommandName()
  {
    return "delwarp";
  }

  public String getCommandUsage(ICommandSender icommandsender)
  {
    return "/" + getCommandName() + " <name>";
  }

  public List getCommandAliases()
  {
    return null;
  }

  public void processCommand(ICommandSender icommandsender, String[] astring)
  {
    if ((icommandsender instanceof EntityPlayer)) {
      EntityPlayer player = (EntityPlayer)icommandsender;

      if (astring.length == 0) {
        player.addChatMessage("This command requires a warp name");
        return;
      }

      String warpName = astring[0];
      String world = player.worldObj.getWorldInfo().getWorldName();

      if (!ConfigHandler.HasCategory(warpName)) {
        player.addChatMessage("The requested warp cannot be found.");
        return;
      }

      ConfigCategory cc = ConfigHandler.getCategory(warpName);

      if (!cc.get("player").getString().equals(player.username)) {
        player.addChatMessage("The requested warp does not exist or belong to you.");
        return;
      }

      if (!cc.get("world").getString().equals(world)) {
        player.addChatMessage("The requested warp does not belong to this world.");
        return;
      }

      ConfigHandler.delCategory(warpName);
      player.addChatMessage("Warp deleted");
    }
  }

  public boolean canCommandSenderUseCommand(ICommandSender icommandsender)
  {
    return true;
  }

  public List addTabCompletionOptions(ICommandSender icommandsender, String[] astring)
  {
    return null;
  }

  public boolean isUsernameIndex(String[] astring, int i)
  {
    return false;
  }
}